import { Base } from "@/js/common/base";
import { LazyLoading } from "@/js/common/lazyLoad";
import { Charming } from "@/js/common/charming";
import Lenis from "lenis";
import { BaseAnimate,HomeFn,NewFn,ContactFn,ApplyFn,TechFn,AboutFn} from './pages/pageFn'

let lenis,base,animate;
animate = new Charming();
new LazyLoading({el:'.lazy'});
const initSmoothScrolling = () => {
    lenis = new Lenis({
        duration: 1.,
        smooth: true,
    });
    const scrollFn = (time) => {
        lenis.raf(time);
        requestAnimationFrame(scrollFn);
    };
    requestAnimationFrame(scrollFn);
}
const animateOnScroll = () => {
    base = new Base();
    BaseAnimate(base,lenis);
    if(base.curPage('.home')){
        window.onbeforeunload = function (){
            if (history.scrollRestoration) {
                history.scrollRestoration = 'manual';
            }else {
                console.log("不支持")
            }
        }
        HomeFn(base,lenis);
    }
    else{document.querySelector('.pcNav').classList.add('go');}
    if(base.curPage('.news')){NewFn(base);}
    if(base.curPage('.contact')){ContactFn(base);}
    if(base.curPage('.application')){ApplyFn(base);}
    if(base.curPage('.tech')){
        window.onbeforeunload = function (){
            if (history.scrollRestoration) {
                history.scrollRestoration = 'manual';
            }else {
                console.log("不支持")
            }
        }
        TechFn(base);
    }
    if(base.curPage('.about')){AboutFn(base);}
}
initSmoothScrolling();
animateOnScroll();
let isChange = ((window.innerWidth/window.innerHeight)>1) ? 1:2;
window.onresize = function(){
    let str = (window.innerWidth/window.innerHeight>1) ? 1:2;
    if(str!==isChange){
        location.reload();
        isChange = str;
    }
}
